﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace Soopah.Xna.Input
{
    [Serializable]
    public class AnalogInput : ISerializable
    {
        public int Index;
        public string XAxis;
        public string YAxis;


        public AnalogInput()
        {
            
        }

        public AnalogInput(SerializationInfo info, StreamingContext context)
        {
            
            Index = info.GetInt32("Index");
            XAxis = info.GetString("XAxis");
            YAxis = info.GetString("YAxis"); ;
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            
            info.AddValue("Index",Index);
            info.AddValue("XAxis",XAxis);
            info.AddValue("YAxis",YAxis);
        }
    }

    [Serializable]
    public class ButtonSettings : ISerializable
    {
        public string Name;
        //Button Indexes
        public int AIndex = -1, BIndex = -1, XIndex = -1, YIndex = -1, LBIndex = -1, RBIndex = -1, BackIndex = -1, StartIndex = -1, LStickIndex = -1, RStickIndex = -1;
        public bool HasLeftStick=false, HasRightStick=false, HasShoulders=false;
        //Stick Indexes
        public List<AnalogInput> Sticks;

        public ButtonSettings()
        {
            Sticks = new List<AnalogInput>();
        }

        public ButtonSettings(SerializationInfo info, StreamingContext context)
        {
            Name = info.GetString("Name");
            AIndex = info.GetInt32("AIndex");
            BIndex = info.GetInt32("BIndex");
            XIndex = info.GetInt32("XIndex");
            YIndex = info.GetInt32("YIndex");
            LBIndex = info.GetInt32("LBIndex");
            RBIndex = info.GetInt32("RBIndex");
            BackIndex = info.GetInt32("BackIndex");
            StartIndex = info.GetInt32("StartIndex");
            LStickIndex = info.GetInt32("LStickIndex");
            RStickIndex = info.GetInt32("RStickIndex");

            HasLeftStick = info.GetBoolean("HasLeftStick");
            HasRightStick = info.GetBoolean("HasRightStick");
            HasShoulders = info.GetBoolean("HasShoulders");

            Sticks = (List<AnalogInput>)info.GetValue("XYAxis", typeof(List<AnalogInput>));
            
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Name", Name);
            info.AddValue("AIndex",AIndex);
            info.AddValue("BIndex", BIndex);
            info.AddValue("XIndex",XIndex);
            info.AddValue("YIndex",YIndex);
            info.AddValue("LBIndex",LBIndex);
            info.AddValue("RBIndex",RBIndex);
            info.AddValue("BackIndex",BackIndex);
            info.AddValue("StartIndex",StartIndex);
            info.AddValue("LStickIndex",LStickIndex);
            info.AddValue("RStickIndex",RStickIndex);

            info.AddValue("HasLeftStick",HasLeftStick);
            info.AddValue("HasRightStick",HasRightStick);
            info.AddValue("HasShoulders", HasShoulders);
            

            info.AddValue("XYAxis", Sticks);
        }

    }
}
